﻿using System;
using System.Data.Entity;

namespace BreakAwayConsole
{
    class Program
    {
        static void Main(string[] args)
        {    //意思就是：如果实体类有变化就重新生成一下数据库(DropCreateDatabaseIfModelChanges)
            //。使用这个方法又得添加引用：using System.Data.Entity;
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataAccess.BreakAwayContext>());

            InsertPerson();
            InsertTrip();
            InsertDestination();
            Console.WriteLine("ok");
            Console.WriteLine("Insertcode");
            Console.WriteLine("123");
            Console.ReadKey();
        }

        /// <summary>
        /// 新增
        /// </summary>
        private static void InsertDestination()
        {
            //对象初始化器来赋值
            var destintation = new Model.Destination()
            {
                Country = "Indonesia",
                Description = "EcoTourism at its best in exquisite Bali",
                Name = "Bali"
            };

            using (var context = new DataAccess.BreakAwayContext())
            {
                context.Destinations.Add(destintation);
                context.SaveChanges();
            }
        }

        /// <summary>
        /// 新增
        /// </summary>
        private static void InsertTrip()
        {
            var trip = new Model.Trip()
            {  //Identifier = new Guid(),
                CostUSD = 12.32M,
                EndDate = new DateTime(2016, 11, 3),
                StartDate = new DateTime(2016, 10, 30)

            };
            using (var context = new DataAccess.BreakAwayContext())
            {
                context.Trips.Add(trip);
                context.SaveChanges();
            }

        }

        /// <summary>
        /// 新增
        /// </summary>
        private static void InsertPerson()
        {
            var person = new Model.Person()
            {
                FirstName = "li",
                LastName = "lh",
                SocialSecurityNumber = 1

            };
            using (var context = new DataAccess.BreakAwayContext())
            {
                context.Persons.Add(person);
                context.SaveChanges();
            }

        }

    }
}
